package com.mrobuy.type;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 上架SKU状态
 *
 *  状态:(  0: 初始; 1: 成功; 2: 失败; 3: 状态异常; 8: 预处理完成 )
 */
public enum ItemState {

    INIT("0", "初始"),

    SUCCESS("1", "成功"),
    FAILED("2", "失败"),
    UNUSUAL("3", "状态异常"),
    READY("8", "预处理完成");

    private final static Map<String, ItemState> map = new ConcurrentHashMap<>();

    static {
        for (ItemState applyState : ItemState.values()) {
            map.put(applyState.code, applyState);
        }
    }

    public static ItemState getStateByCode(Integer code){
        if ( map.containsKey(code) ) {
            return map.get(code);
        }

        return INIT;
    }

    private String code;
    private String desc;

    ItemState(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String code() {
        return code;
    }

    public String desc() {
        return desc;
    }
}
